import { getCartListAPI } from '@/api/cart'
import { useCartStore } from '@/stores/modules/cart'
import type { CartItemResult } from '@/types/cart'
import { ref } from 'vue'

export default function () {
  const cartStore = useCartStore()
  // 购物车列表
  const cartList = ref<CartItemResult[]>([])
  // 获取购物车列表
  const getCartList = async (businessId: number) => {
    try {
      const { data } = await getCartListAPI(businessId)
      cartList.value = data
      cartStore.setCart(data)
    } catch (error) {
      console.log(error)
    }
  }
  return {
    cartList,
    getCartList,
  }
}
